﻿<!--
ChangeTracking (a library for POCO change tracking).

Copyright (C) 2014 Dmitry Merzagitovich Arslanov

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-->

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    x:Class="ChangeTrackingSample.MainWindow"
    x:Name="Wnd"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ChangeTracking Sample"
    MinWidth="525"
    MinHeight="350"
    Width="525"
    Height="350"
    WindowStartupLocation="CenterScreen"
    Closing="WndClosing">
    <Window.Resources>
        <RoutedUICommand
            x:Key="AddCommand"
            Text="Add" />
        <RoutedUICommand
            x:Key="RemoveCommand"
            Text="Remove" />
        <RoutedUICommand
            x:Key="ModifyCommand"
            Text="Modify" />
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding
            Command="New"
            CanExecute="CanNew"
            Executed="New" />
        <CommandBinding
            Command="Open"
            CanExecute="CanOpen"
            Executed="Open" />
        <CommandBinding
            Command="Save"
            CanExecute="CanSave"
            Executed="Save" />
        <CommandBinding
            Command="SaveAs"
            CanExecute="CanSaveAs"
            Executed="SaveAs" />
        <CommandBinding
            Command="Close"
            CanExecute="CanClose"
            Executed="Close" />
        <CommandBinding
            Command="{StaticResource AddCommand}"
            CanExecute="CanAdd"
            Executed="Add" />
        <CommandBinding
            Command="{StaticResource RemoveCommand}"
            CanExecute="CanRemove"
            Executed="Remove" />
        <CommandBinding
            Command="{StaticResource ModifyCommand}"
            CanExecute="CanModify"
            Executed="Modify" />
        <CommandBinding
            Command="Undo"
            CanExecute="CanUndo"
            Executed="Undo" />
        <CommandBinding
            Command="Redo"
            CanExecute="CanRedo"
            Executed="Redo" />
    </Window.CommandBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition
                Height="Auto" />
            <RowDefinition />
            <RowDefinition
                Height="Auto" />
        </Grid.RowDefinitions>
        <Menu>
            <MenuItem
                Header="File">
                <MenuItem
                    Command="New" />
                <MenuItem
                    Command="Open" />
                <MenuItem
                    Command="Save" />
                <MenuItem
                    Command="SaveAs" />
                <MenuItem
                    Command="Close" />
            </MenuItem>
            <MenuItem
                Header="Edit">
                <MenuItem
                    Command="Undo" />
                <MenuItem
                    Command="Redo" />
                <Separator />
                <MenuItem
                    Command="{StaticResource AddCommand}" />
                <MenuItem
                    Command="{StaticResource ModifyCommand}" />
                <MenuItem
                    Command="{StaticResource RemoveCommand}" />
            </MenuItem>
        </Menu>
        <DataGrid
            x:Name="DataGrid"
            Grid.Row="1"
            IsReadOnly="True"
            AutoGenerateColumns="False"
            ItemsSource="{Binding ElementName=Wnd, Path=Document.Database.Entities}"
            SelectionMode="Single"
            SelectionUnit="FullRow">
            <DataGrid.Columns>
                <DataGridTextColumn
                    Header="Name"
                    Binding="{Binding Path=Name}" />
                <DataGridTextColumn
                    Header="Value"
                    Binding="{Binding Path=Value}" />
            </DataGrid.Columns>
        </DataGrid>
        <StatusBar
            Grid.Row="2">
            <StatusBarItem>
                <TextBlock>
                    <TextBlock.Style>
                        <Style
                            TargetType="TextBlock">
                            <Style.Triggers>
                                <DataTrigger
                                    Binding="{Binding ElementName=Wnd, Path=Document.Tracker.Changed}"
                                    Value="True">
                                    <Setter
                                        Property="Text"
                                        Value="Has changes" />
                                    <Setter
                                        Property="FontWeight"
                                        Value="Bold" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>
